this.main=function() {
	
	var oldData=pageoldData();
	var tn=this.tablename;
	var fieldnameList=null;
	var objdata={};
	var gridInfo=null;
	var formValue=null;
	if(oldData!=null){
		fieldnameList=oldData.fieldnameList;
	    objdata=oldData.objdata;
	    gridInfo=oldData.gridInfo;
	    formValue=oldData.form;
	   
	}
	
	
	var defaultField=defaultFormfield();
	

var setProps={
		height:function(field,value){
			field.setHeight(value);
		},
		width:function(field,value){
			field.setWidth(value);
		},
		colspan:function(field,value){
			var index=displayForm.items.indexOf(field);
			var e=displayForm.remove(field);
			
			e=createObj(e);
			e.colspan=value;
			displayForm.insert(index,e);
			displayForm.doLayout(false);
			
		},
		fieldLabel:function(field,value){
			field.getEl().up('.x-form-item').child('.x-form-item-label').dom.innerHTML =value;
		}
		
	}
function createObj(record){
	var obj=objdata[record.name];
	var r={
		id:"ext-dicformcfg-"+menuide+record.name,
		readOnly:true,
		name:record.name,
		value:record.name,
		fieldLabel:record.cnname,
		xtype:'textfield',
		onBlur : function(){
	        this.beforeBlur();
	        if(this.focusClass){
	            this.el.removeClass(this.focusClass);
	        }
	        this.hasFocus = false;
	        if(this.validationEvent !== false && (this.validateOnBlur || this.validationEvent == 'blur')){
	            this.validate();
	        }
	        var v = this.getValue();
	        if(String(v) !== String(this.startValue)){
	            this.fireEvent('change', this, v, this.startValue);
	        }
	        this.fireEvent('blur', this);
	        this.postBlur();
    	},listeners:{focus:function(f){load(f);}}
		}
	if(obj==null){
		objdata[record.name]=Ext.applyIf({name:record.name,
		fieldLabel:record.cnname,a00type:'textfield'
		},defaultField);
		if(record.sourcetable)
		objdata[record.name].sourcetable=record.sourcetable;
		if(record.sourcecolumn)
		objdata[record.name].sourcecolumn=record.sourcecolumn
		
		
	}else{
		for(var name in setProps){
			var value=objdata[record.name][name];
			if(value!==0)
				r[name]=value;
		}
	}
	return r;
	
}





function load(f){
	propsGrid.stopEditing();
	if(f==null)
		return;
	if(propsGrid.colname!=null){
		var oldel=Ext.getCmp("ext-dicformcfg-"+menuide+propsGrid.colname);
		if(oldel!=null){
			oldel.removeClass('divFindBorder');
			oldel.getEl().up('.x-form-item').removeClass('divFindBorder');
		}
	}
	propsGrid.setSource(objdata[f.name]);
	propsGrid.colname=f.name;
	f.addClass('divFindBorder'); 
	f.getEl().up('.x-form-item').addClass('divFindBorder');
}

var menuide=this.menuid;

function displayFormLayoutUpdate(){
var formp=Ext.getCmp('downform'+menuide).form.getValues(false);
	displayForm.layout.columns=formp.colnum;
	displayForm.layout.labelStyle="width:"+formp.labelWidth+"px;";
	displayForm.layout.elementStyle="padding-left:"+(parseInt(formp.labelWidth)+5)+"px;";
	displayForm.labelWidth=parseInt(formp.labelWidth);
	displayForm.layout.labelSeparator=formp.labelSeparator;
	displayForm.removeClass('x-form-label-' + displayForm.labelAlign);
	displayForm.labelAlign=formp.labelAlign;
	displayForm.addClass('x-form-label-' + displayForm.labelAlign);
}


function displayFromFun(){
	
	displayForm.removeAll(true);
	
	displayFormLayoutUpdate();
	var objarray=[];
	var records = grid.getSelectionModel().getSelections();
	if (records.length <= 0) {
			Ext.MessageBox.alert('提示', '请至少选择一列');
		return;
	}
	var store =grid.getStore(); 
	for(var i=0;i<records.length;i++)
	{	
		var record=records[i].data;
		var nobj=createObj(record);
		objarray[store.indexOf(records[i])]=nobj;
	}
	var addarray=[]
	for(var i=0;i<objarray.length;i++){
		if(objarray[i]!=null)
			addarray.push(objarray[i]);
	}
		displayForm.add(addarray);
	
	displayForm.getLayout().clearTableRows();
	displayForm.doLayout(false);

}
	var grid=getFormGird(displayFromFun,fieldnameList,tn);
	var store=grid.store;
	
	
	var displayForm=new Ext.form.FormPanel({
		layout:"tableForm",
		region : 'center',
		split:true,
		frame : true,
		height:frame_center.getInnerHeight()-275,
		border: false,
		//labelWidth:60,
		defaults:{
			defaults:{anchor: '90%'},
			layout : 'form',
			width :150 ,
			xtype:'textfield',
			colspan:1},
		layoutConfig:{columns:2}
	});
	
	var fieldtypeComboBox=new Ext.grid.GridEditor(new Ext.form.ComboBox({  
				width :260,
	            editable: false,  
	            displayField : "fieldname",
				valueField : "fieldtype",
	            mode: "local",  
	            triggerAction: "all",
	            listeners:{
	            	select:function(){
	            				var atype=this.getValue();;
	            				Ext.Ajax.request({
								method : 'GET',// 为了不丢失js文件内容，所以要选择post的方式加载js文件
								url : basepath+"../sysControl/formcfg/DicTablePageCfgController/getFormfieldProperty.do",
								params : {fieldtype:atype},
								success : function(response) {
									var obj=Ext.util.JSON.decode(response.responseText);
									var oldobj=propsGrid.getSource();
									propsGrid.stopEditing(false);
						            for(var p in oldobj){
						                if(Ext.isDefined(obj[p])){
						                   obj[p] = oldobj[p];
						               }
						           }
						          obj.a00type=atype;
						          objdata[propsGrid.colname]=obj;
								  propsGrid.setSource(objdata[propsGrid.colname]);
								}
							});
	            	}
	            } ,
	            store: new Ext.data.Store({
	            		autoLoad:true,
						proxy : new Ext.data.HttpProxy({
							url :  basepath+"../sysControl/formcfg/DicTablePageCfgController/getFormfieldList.do"
						}),
						reader : new Ext.data.JsonReader({
							id : "fieldtype"
						}, Ext.data.Record.create([{
							name : 'fieldid',
							type : 'int'
						}, {
							name : "fieldname",
							type : 'string'
						}, {
							name : "fieldtype",
							type : 'string'
						}]))
					})
	        }))
	        
	
	
	var propsGrid = new Ext.grid.PropertyGrid({
        stripeRows :true,
         onRender : function(){
           this.getColumnModel().setColumnWidth(0,328,true);
    	   this.getColumnModel().setColumnWidth(1,630,true);
         	
        	Ext.grid.PropertyGrid.superclass.onRender.apply(this, arguments);
        
        	this.getGridEl().addClass('x-props-grid');
        	
        	
   		 },
        listeners:{
       		afteredit:function(value ){
	        	try{
	       
	        	var data=value.record.data;
	        	var v=value.value;
	        	var fun=setProps[data.name]
	        	if(fun){
	        		var dicformcfg=Ext.getCmp("ext-dicformcfg-"+menuide+propsGrid.colname);
	        	
	        		if(dicformcfg)
	        		fun(dicformcfg, v);
	        		
	        	}
	        	}catch(e){
	        	
	        	
	        	}
	        	
        }},
   	    viewConfig :{
       	 forceFit:false,
       	 scrollOffset: 2 // the grid will never have scrollbars

    	},
		customEditors:{
			a00type:fieldtypeComboBox
		},
        region:'south',
        height : 245,
        split:true,
    	border: false,
        autoScroll : true,
        propertyNames: propertyNames(),
        source: {
            
        }
    });
   
   
	var mainForm=new Ext.Panel({
		layout:'border',
		height:frame_center.getInnerHeight(),
		renderTo:'divLlist'+this.menuid,
		tbar : [{
			text : '保存',
			iconCls : 'table_save',
			handler : function() {
				var items=displayForm.items;
				if(items.length<=0){
					Ext.MessageBox.alert('提示', '请至少选择一列');
					return ;
				}
				if(gridInfo==null){
					Ext.MessageBox.alert('提示', '请点击[表格设置 ]设置表格');
					return ;
				}
				var myfields=[];
				var formp=Ext.getCmp('downform'+menuide).form.getValues(false);
				for(var i=0,n=items.length;i<n;i++){
					myfields.push(objdata[items.itemAt(i).getName()]);					
					
				}
				formp.field=myfields;
				
				var json=Ext.util.JSON.encode({form:formp,grid:{dataRecords_record:gridInfo.dataRecord,colModels_col:gridInfo.colModel}});
				Ext.Ajax.request({
								method : 'POST',// 为了不丢失js文件内容，所以要选择post的方式加载js文件
								url : basepath+"../sysControl/formcfg/DicTablePageCfgController/saveXML.do",
								params : {json:json,tablename:tn},
								success : function(response) {
									alertpand(response.responseText);
								}
							});
				
			}
		},{
			text : '表格设置',
			iconCls : 'table_attach',
			handler : function(){
				var record = grid.getSelectionModel().getSelections();
				if (record.length <= 0) {
						Ext.MessageBox.alert('提示', '请至少选择一列');
						return;
					}
				
				openGridCfgWindow(record,gridInfo,function(gridInfo1){gridInfo=gridInfo1});
			}
		},'->',
		{xtype:'closePage'}
		],
		items:[{xtype:'container',width:242,region : 'west',height:frame_center.getInnerHeight(),items:[grid,
			 {
				region : 'center',
				xtype : 'form',
				frame : false,
				labelWidth : 70,
				autoHeight : true,
				id:'downform'+this.menuid,
				labelAlign : 'right',
				title : 'form属性',
				defaults : {
					anchor : '92%'
				},
				bodyStyle : 'padding:8px 2px 2px 2px;',
				items : [{
					      
							xtype : 'textfield',
							fieldLabel : '标题',
							name : 'title',
							maxLength : 30
						}, {
							xtype : 'textfield',
							fieldLabel : 'label分隔符',
							name : 'labelSeparator',
							value:'',
							maxLength : 30
						}, {
							xtype : 'numberfield',
							fieldLabel : 'label宽度',
							value:60,
							name : 'labelWidth',
							maxLength : 30
						},	{
							xtype : 'combo',
							fieldLabel : 'label位置',
							hiddenName : 'labelAlign',
							maxLength : 12,
							name:'labelAlignCombo',
							triggerAction : 'all',
							mode : 'local',
							editable : false,
							value:'right',
							valueField : 'value',
							displayField : 'text',
							store : new Ext.data.SimpleStore({
								fields : [ 'value', 'text' ],
								data : [ [ 'left', '左' ], [ 'top', '上' ],[ 'right', '右' ] ]
							})
						}, {
							xtype : 'numberfield',
							fieldLabel : '列数',
							value:2,
							name : 'colnum',
							maxLength : 30
						}, {
							xtype : 'numberfield',
							fieldLabel : '列间距',
							name : 'colspacing',
							value:0,
							maxLength : 30
						}, {
							xtype : 'numberfield',
							fieldLabel : '行间距',
							name : 'rowpacing',
							value:0,
							maxLength : 30
						}]
			
			}
				]},
			   {xtype:'container',height:frame_center.getInnerHeight(),region : 'center',items:[displayForm,propsGrid]}]
	});
	if(formValue!=null)
		Ext.getCmp('downform'+menuide).form.setValues(formValue);

	destroyResize(mainForm,[propsGrid,fieldtypeComboBox]);
}
